package cn.itcast.xuesheng.web.logger;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component("Logger")
@Aspect
public class Logger {

    @Pointcut("execution(* cn.itcast.xuesheng.service.impl.UserServiceImpl.*(..))")
    private void  pt1(){

    }

    @Around("pt1()")
    public Object aroundLogger(ProceedingJoinPoint proceedingJoinPoint){
        Object obj = null;
        try {
            System.out.println("开始记录日志了");
            Object[] args = proceedingJoinPoint.getArgs();
            obj = proceedingJoinPoint.proceed(args);
            System.out.println("方法完成");
        }
        catch (Throwable throwable){
            System.out.println("出现异常");
        }
        finally {
            System.out.println("日志记录结束了");
        }
        return obj;
    }
}
